#include <iostream>
using namespace std;

bool check_half(int* sz, int len, int number) {
	int times = 0;
	for (int i = 0; i < len; i++) {
		if (sz[i] == number)
			times++;
	}

	if (times >= len/2)
		return true;
	else
		return false;
}

int get_half(int* sz, int len) {
	int times = 1, number = sz[0];
	for (int i=1; i<len; i++) {
		if (times == 0) {
			number = sz[i];
			times = 1;
		}
		else if (sz[i] == number)
			times++;
		else
			times--;
	}

	if (!check_half(sz, len, number))
		number = -1;

	return number;
}

//int main() {
//	int sz[] = {1,2,2,2,3,4,4,4,4,5,4,4};
//	int ret = get_half(sz, 12);
//	return 0;
//}